-
Notifications
You must be signed in to change notification settings - Fork 374
[INFERENCE PROVIDERS] guide on structured output #1824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
| - local: guides/building-first-app | ||
| title: Building Your First AI App | ||
| - local: guides/structured-output | ||
| title: Structured Outputs with LLMs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would align the toctree title with the doc title (or vice versa) to avoid confusion for users when referencing the doc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't the guides be under the provider list?
i think we want to focus on providers more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(forgot to post this on the previous PR @burtenshaw sorry =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries. I'll make another PR with the menu change.
| @@ -0,0 +1,467 @@ | |||
| # Structured Outputs with Inference Providers | |||
|
|
|||
| In this guide, we'll show you how to use Inference Providers to generate structured outputs that follow a specific JSON schema. This is incredibly useful for building reliable AI applications that need predictable, parseable responses. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| In this guide, we'll show you how to use Inference Providers to generate structured outputs that follow a specific JSON schema. This is incredibly useful for building reliable AI applications that need predictable, parseable responses. | |
| In this guide, we'll show you how to use Inference Providers to generate structured outputs that follow a specific JSON schema. This is incredibly useful for building reliable AI applications that need predictable, parsable responses. |
|
|
||
| We'll create a simple schema that captures the most essential elements: the paper's title and a summary of its abstract. The easiest way to do this is to use Pydantic, a library that allows you to define Python classes that represent JSON schemas (among other things). | ||
|
|
||
| <hfoptions id="json-pydantic"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't use the toggles here since it sets up as a kind of "choose one or the other". After showing the Pydantic code example, maybe transition with:
"The Pydantic represented JSON schema is shown below."
|
|
||
| </hfoption> | ||
|
|
||
| The OpenAI client returns a `ChatCompletion` object, which contains the response from the model as a Python object. You can then access the structured data using the `title` and `abstract_summary` attributes of the `PaperAnalysis` class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go under the <hfoption id="openai"> toggle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool doc page, is there one about tool calling coming up as well? :)
Note, @SBrandeis has been building some validation matrix of model/provider support for structured output & function calling, we could dynamically display it here in this page (or link to it from this page)
cc @gary149 too for viz
Yep. It's coming tomorrow.
👍 |
|
|
||
| ## Step 2: Set up your inference client | ||
|
|
||
| Now that we have our schema defined, let's set up the client to communicate with the inference providers. We'll show you two approaches: the Hugging Face Hub client (which gives you direct access to all Inference Providers) and the OpenAI client (which works through OpenAI-compatible endpoints). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadge - it's only Python 🥲
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true. I'll come back to that on all new guides.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very useful !!
Co-authored-by: Steven Liu <[email protected]>
…ace/hub-docs into guide-structured-output
This PR adds a guide on structured outputs with inference providers. It uses hf client, openai client, cerebras, qwen3 32b